
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Kubernetes 命令概览 · Kubernetes - 痴者工良</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="痴者工良">
        
        
    
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="ckad.html" />
    
    
    <link rel="prev" href="8.health/README.md" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.whuanle.cn" target="_blank" class="custom-link">痴者工良的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    文档说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="1.basic/">
            
                <a href="1.basic/">
            
                    
                    1.基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="1.basic/">
            
                <a href="1.basic/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="1.basic/1.docker.html">
            
                <a href="1.basic/1.docker.html">
            
                    
                    1.1 说透 Docker：基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="1.basic/2.virtual.html">
            
                <a href="1.basic/2.virtual.html">
            
                    
                    1.2 说透 Docker： 虚拟化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="1.basic/3.docker_network.html">
            
                <a href="1.basic/3.docker_network.html">
            
                    
                    1.3 了解 Docker 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="1.basic/4.pod_docker.html">
            
                <a href="1.basic/4.pod_docker.html">
            
                    
                    1.4 Docker 和 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="1.basic/5.k8s.html">
            
                <a href="1.basic/5.k8s.html">
            
                    
                    1.5 K8S入门基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="2.deploy/">
            
                <a href="2.deploy/">
            
                    
                    2.部署和配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="2.deploy/2.deploy.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="2.deploy/1.minikube.html">
            
                <a href="2.deploy/1.minikube.html">
            
                    
                    2.1 使用 Minikube 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="2.deploy/2.kubeadm.html">
            
                <a href="2.deploy/2.kubeadm.html">
            
                    
                    2.2 使用 kubeadm 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="2.deploy/3.kubeadm_ckad.html">
            
                <a href="2.deploy/3.kubeadm_ckad.html">
            
                    
                    2.3 CKAD认证中的部署教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="2.deploy/4.kubeadm_proxy.html">
            
                <a href="2.deploy/4.kubeadm_proxy.html">
            
                    
                    2.4 国内代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="2.deploy/5.dashboard.html">
            
                <a href="2.deploy/5.dashboard.html">
            
                    
                    2.5 Dashboard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="3.pod/">
            
                <a href="3.pod/">
            
                    
                    3.Pod部署和调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="3.pod/">
            
                <a href="3.pod/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="3.pod/1.pod.html">
            
                <a href="3.pod/1.pod.html">
            
                    
                    3.1 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="3.pod/2.deployment.html">
            
                <a href="3.pod/2.deployment.html">
            
                    
                    3.2 Deployment部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="3.pod/3.replica.html">
            
                <a href="3.pod/3.replica.html">
            
                    
                    3.3 副本集(ReplicaSet)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="3.pod/4.pod_network.html">
            
                <a href="3.pod/4.pod_network.html">
            
                    
                    3.34 Pod 端口映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="3.pod/5.update.html">
            
                <a href="3.pod/5.update.html">
            
                    
                    3.5 Pod 升级、回滚
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="3.pod/6.scale.html">
            
                <a href="3.pod/6.scale.html">
            
                    
                    3.6 Pod 缩放
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="3.pod/7.lable.html">
            
                <a href="3.pod/7.lable.html">
            
                    
                    3.7.Pod 标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="3.pod/8.schedule.html">
            
                <a href="3.pod/8.schedule.html">
            
                    
                    3.8 Pod 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="3.pod/9.jobs_cronjobs.html">
            
                <a href="3.pod/9.jobs_cronjobs.html">
            
                    
                    3.9 Jobs、CronJobs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="4.network/">
            
                <a href="4.network/">
            
                    
                    4.Kubernetes 网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="4.network/">
            
                <a href="4.network/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="4.network/1.network.html">
            
                <a href="4.network/1.network.html">
            
                    
                    4.1 Kubernetes 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="4.network/2.endpoint.html">
            
                <a href="4.network/2.endpoint.html">
            
                    
                    4.2 Endpoint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="4.network/3.ingress.html">
            
                <a href="4.network/3.ingress.html">
            
                    
                    4.3 ingress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="4.network/4.discovery.html">
            
                <a href="4.network/4.discovery.html">
            
                    
                    4.4 服务发现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="5.volumes/">
            
                <a href="5.volumes/">
            
                    
                    5.volumes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="5.volumes/">
            
                <a href="5.volumes/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="5.volumes/1.volumes.html">
            
                <a href="5.volumes/1.volumes.html">
            
                    
                    5.1 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="5.volumes/2.secret_configmap.html">
            
                <a href="5.volumes/2.secret_configmap.html">
            
                    
                    5.2 secret 和 ConfigMap 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="5.volumes/3.nfts.html">
            
                <a href="5.volumes/3.nfts.html">
            
                    
                    5.3 NFS卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="5.volumes/4.pv_pvc.html">
            
                <a href="5.volumes/4.pv_pvc.html">
            
                    
                    5.4 持久化卷
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="6.api_safe/">
            
                <a href="6.api_safe/">
            
                    
                    6.API 和 安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="6.api_safe/">
            
                <a href="6.api_safe/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="7.health/">
            
                <a href="7.health/">
            
                    
                    7.维护和故障排除
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="8.health/README.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.9" data-path="k8s.html">
            
                <a href="k8s.html">
            
                    
                    Kubernetes 命令概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="ckad.html">
            
                <a href="ckad.html">
            
                    
                    CKAD 认证帮助
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Kubernetes 命令概览</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p><strong>&#x4F7F;&#x7528; Json &#x8868;&#x8FBE;&#x5F0F;&#x7B5B;&#x9009;&#x5B57;&#x6BB5;</strong></p>
<p>&#x5982;&#x679C;&#x662F;&#x5355;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x4F8B;&#x5982; Pod test&#xFF0C;&#x90A3;&#x4E48;&#x83B7;&#x53D6;&#x5176;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pod <span class="token builtin class-name">test</span> -o<span class="token operator">=</span>jsonpath<span class="token operator">=</span><span class="token string">&quot;{.metadata.namespace}&quot;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x662F;&#x591A;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x4F7F;&#x7528; <code>.item[*]</code>&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -o<span class="token operator">=</span>jsonpath<span class="token operator">=</span><span class="token string">&quot;{.item[*].metadata.namespace}&quot;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x83B7;&#x53D6;&#x591A;&#x4E2A;&#x5B57;&#x6BB5;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -o<span class="token operator">=</span>jsonpath<span class="token operator">=</span><span class="token string">&quot;{.items[*][&apos;metadata.name&apos;, &apos;metadata.namespace&apos;]}&quot;</span>
</code></pre>
<p>&#x67E5;&#x770B; Pod &#x7684;&#x5BB9;&#x5668;&#x955C;&#x50CF;&#x5217;&#x8868;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get po nginx -o <span class="token assign-left variable">jsonpath</span><span class="token operator">=</span><span class="token string">&apos;{.spec.containers[].image}{&quot;\n&quot;}&apos;</span>
</code></pre>
<p>&#x83B7;&#x53D6; skywalker &#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E0B;&#x5E26;&#x6709; <code>jedi=true</code> &#x6807;&#x7B7E;&#x7684; Pod &#x7684;&#x540D;&#x79F0;&#x548C;&#x955C;&#x50CF;&#x540D;&#x79F0;&#xFF0C;&#x8F93;&#x51FA;&#x683C;&#x5F0F;&#xFF1A;<code>podname,imagename</code>&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl get po  -n skywalker --selector<span class="token operator">=</span>jedi<span class="token operator">=</span>true -o <span class="token assign-left variable">jsonpath</span><span class="token operator">=</span><span class="token string">&quot;{range .items[*]}{.metadata.name},{.spec.containers[0].image}{&apos;<span class="token entity" title="\n">\n</span>&apos;}{end}&quot;</span>
</code></pre>
<p><strong>&#x521B;&#x5EFA; Pod</strong></p>
<p>&#x5728;&#x65E7;&#x7248;&#x672C;&#x7684; kubectl &#x4E2D;&#xFF0C;&#x4F7F;&#x7528; <code>kubectl run</code> &#x53EF;&#x4EE5;&#x521B;&#x5EFA; Pod &#x548C; Deployment &#x7B49;&#xFF0C;&#x4F46;&#x662F;&#x524D;&#x9762;&#x4E0D;&#x9700;&#x8981;&#x52A0;&#x4E0A;&#x8D44;&#x6E90;&#x7C7B;&#x578B;&#xFF0C;&#x800C;&#x662F;&#x6839;&#x636E;&#x540E;&#x9762;&#x7684;&#x53C2;&#x6570;&#x51B3;&#x5B9A;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x521B;&#x5EFA; Pod</span>
kubectl run nginx --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never
<span class="token comment"># &#x521B;&#x5EFA; Deployment</span>
kubectl run nginx --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Alway
</code></pre>
<p>&#x4F46;&#x662F;&#x65B0;&#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x6B67;&#x4E49;&#x548C;&#x8FC7;&#x591A;&#x7684;&#x53C2;&#x6570;&#xFF0C; <code>kubectl run</code> &#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x529F;&#x80FD;&#xFF0C;&#x521B;&#x5EFA; Pod&#xFF0C;&#x6240;&#x4EE5;&#x4F7F;&#x7528; <code>kubectl run</code> &#x547D;&#x4EE4;&#xFF0C;&#x540E;&#x9762;&#x4E0D;&#x9700;&#x8981;&#x52A0;&#x4E0A; <code>--restart=Never</code> &#x4E86;&#x3002;</p>
<p>&#x5176;&#x5B9E;&#x6CA1;&#x5FC5;&#x8981;&#x52A0;&#xFF0C;&#x56E0;&#x4E3A;&#x6709;&#x4E9B;&#x6559;&#x6750;&#x65E7;&#x4E86;&#xFF0C;&#x5BFC;&#x81F4;&#x5B66;&#x4E60;&#x8005;&#x4E0D;&#x77E5;&#x60C5;&#xFF0C;&#x7EE7;&#x7EED;&#x52A0;&#x4E0A;&#x53BB;&#x4E86;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x8DDF;&#x7740;&#x52A0;&#x5427;&#x3002;</p>
<p>&#x53E6;&#x5916;&#xFF0C;Pod &#x6CA1;&#x6709; <code>--export</code> &#x53C2;&#x6570;&#x4E86;&#xFF0C;<code>kubectl get po nginx -o yaml --export</code> &#x547D;&#x4EE4;&#x662F;&#x4E0D;&#x5BF9;&#x7684;&#x3002;</p>
<p>&#x4F7F;&#x7528; YAML &#x521B;&#x5EFA; Pod&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x547D;&#x4EE4;&#x8F93;&#x51FA; YAML &#x6587;&#x4EF6;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run nginx --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never --dry-run<span class="token operator">=</span>client -o yaml <span class="token operator">&gt;</span> nginx-pod.yaml
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x542F;&#x52A8;&#x4E00;&#x4E2A;&#x5E26;&#x547D;&#x4EE4;&#x7684; Pod &#x5462;&#xFF1F;&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run nginx --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never -o yaml --dry-run<span class="token operator">=</span>client -- <span class="token function">sleep</span> <span class="token number">3600</span>
</code></pre>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> sleep
    <span class="token punctuation">-</span> <span class="token string">&quot;3600&quot;</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
</code></pre>
<p>&#x5982;&#x679C;&#xFF0C;&#x8981;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x547D;&#x4EE4;&#xFF0C;&#x5E76;&#x4E14;&#x66FF;&#x6362;&#x5BB9;&#x5668;&#x4E2D;&#x9ED8;&#x8BA4;&#x7684;&#x542F;&#x52A8;&#x547D;&#x4EE4;&#xFF08;&#x4F46;&#x662F;&#x4E0D;&#x8981;&#x8FD9;&#x6837;&#x505A;&#xFF0C;&#x5177;&#x4F53;&#x770B;&#x4E0B;&#x4E00;&#x6761;&#xFF09;&#xFF1A;</p>
<pre class="language-"><code>kubectl run nginx --image=nginx --restart=Never -o yaml --dry-run=client --command -- sleep 3600
</code></pre><pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">command</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> sleep
    <span class="token punctuation">-</span> <span class="token string">&quot;3600&quot;</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
</code></pre>
<p>&#x8BF7;&#x7559;&#x610F;&#x4E24;&#x4E2A; YAML &#x7684;&#x533A;&#x522B;&#xFF0C;&#x524D;&#x8005;&#x662F; args&#xFF0C;&#x540E;&#x8005;&#x662F; command&#x3002;</p>
<p>&#x4F46;&#x662F;&#x5982;&#x679C;&#x8981;&#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49;&#x547D;&#x4EE4;&#xFF0C;&#x4E00;&#x822C;&#x90FD;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run busybox --image<span class="token operator">=</span>busybox --restart<span class="token operator">=</span>Never --command -o yaml --dry-run<span class="token operator">=</span>client -- /bin/sh -c <span class="token string">&quot;sleep 3600&quot;</span>
</code></pre>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> busybox
  <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">command</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> /bin/sh
    <span class="token punctuation">-</span> <span class="token punctuation">-</span>c
    <span class="token punctuation">-</span> sleep 3600
    <span class="token key atrule">image</span><span class="token punctuation">:</span> busybox
    <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
</code></pre>
<p>&#x5F3A;&#x5236;&#x5220;&#x9664; Pod&#xFF0C;&#x5728;&#x540E;&#x9762;&#x52A0;&#x4E0A;&#x4E00;&#x4E2A; <code>--force</code> &#x53C2;&#x6570;&#x5373;&#x53EF;&#xFF0C;&#x8FD9;&#x6837;&#x5220;&#x9664; Pod &#x65F6;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x7B49;&#x5F85;&#x592A;&#x957F;&#x65F6;&#x95F4;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl delet pod nginx --force
</code></pre>
<p>&#x5982;&#x679C;&#x4F60;&#x8FDE;&#x7B49;&#x90FD;&#x4E0D;&#x60F3;&#x7B49;&#xFF0C;&#x53EF;&#x4EE5;&#x52A0;&#x4E0A; <code>--wait=false</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"> kubectl delete pod nginx --force --wait<span class="token operator">=</span>false
</code></pre>
<p>&#x5C06; Pod &#x90E8;&#x7F72;&#x5230;&#x67D0;&#x4E2A;&#x8282;&#x70B9;&#xFF1A;</p>
<pre class="language-"><code>kubectl run nginx --image=nginx --restart=Never --dry-run=client -o yaml
</code></pre><p>&#x7136;&#x540E;&#x5728; YAML &#x52A0;&#x4E0A;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">nodeSelector</span><span class="token punctuation">:</span>
    <span class="token key atrule">nodeName</span><span class="token punctuation">:</span> nginxnode
</code></pre>
<p><strong>&#x955C;&#x50CF;&#x66F4;&#x65B0;</strong></p>
<p>&#x955C;&#x50CF;&#x66F4;&#x65B0;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token builtin class-name">set</span> image pod nginx <span class="token assign-left variable">nginx</span><span class="token operator">=</span>nginx:1.15-alpine
<span class="token comment"># kubectl set image pod nginx nginx=nginx:1.15-alpine --record</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x662F; <code>{&#x955C;&#x50CF;&#x540D;&#x79F0;}={&#x955C;&#x50CF;&#x540D;&#x79F0;}:{&#x7248;&#x672C;}</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F; <code>--image=nginx:1.15-alpine</code>&#x3002;</p>
<p>&#x67E5;&#x770B;&#x5386;&#x53F2;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl rollout <span class="token function">history</span> pod nginx
<span class="token comment"># kubectl rollout history deployment nginx</span>
</code></pre>
<p>&#x56DE;&#x9000;&#x4E0A;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl rollout undo deployment nginx
</code></pre>
<p>&#x67E5;&#x770B;&#x66F4;&#x65B0;&#x72B6;&#x6001;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl rollout status deployment nginx
</code></pre>
<p>&#x6307;&#x5B9A;&#x56DE;&#x6EDA;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl rollout <span class="token function">history</span> deploy webapp --revision<span class="token operator">=</span><span class="token number">7</span>
</code></pre>
<p>&#x6682;&#x505C;&#x3001;&#x6062;&#x590D;&#x66F4;&#x65B0;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl rollout pause deploy webapp
kubectl rollout resume deploy webapp
</code></pre>
<p><strong>&#x6392;&#x5E8F;</strong></p>
<p>&#x4F7F;&#x7528;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token function">top</span> pod -A
</code></pre>
<p>&#x6309;&#x7167; cpu &#x4F7F;&#x7528;&#x91CF;&#x6392;&#x5E8F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token function">top</span> pod -A --sort-by<span class="token operator">=</span>cpu
</code></pre>
<p>&#x6309;&#x7167; &#x5185;&#x5B58; &#x4F7F;&#x7528;&#x91CF;&#x6392;&#x5E8F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token function">top</span> pod -A --sort-by<span class="token operator">=</span>memory
</code></pre>
<p>Pod &#x6309;&#x7167;&#x540D;&#x79F0;&#x6392;&#x5E8F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods --sort-by<span class="token operator">=</span>.metadata.name
</code></pre>
<p>Pod &#x6309;&#x7167;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&#x6392;&#x5E8F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods--sort-by<span class="token operator">=</span>.metadata.creationTimestamp
</code></pre>
<p><strong>&#x6267;&#x884C;&#x547D;&#x4EE4;</strong></p>
<p>&#x4EE5;&#x7EC8;&#x7AEF;&#x7684;&#x663E;&#x793A;&#x6267;&#x884C;&#x547D;&#x4EE4;&#xFF0C;&#x6B64;&#x65F6;&#x5F53;&#x524D;&#x7EC8;&#x7AEF;&#x4F1A;&#x8FDB;&#x5165;&#x5230; Pod &#x5BB9;&#x5668;&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5BB9;&#x5668;&#x4E2D;&#x7684;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run busybox --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never -it -- <span class="token builtin class-name">echo</span> <span class="token string">&quot;How are you&quot;</span>
</code></pre>
<p>&#x6267;&#x884C;&#x547D;&#x4EE4;&#x540E;&#x81EA;&#x52A8;&#x5220;&#x9664; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run busybox --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never -it --rm -- <span class="token builtin class-name">echo</span> <span class="token string">&quot;How are you&quot;</span>
</code></pre>
<p><strong>&#x521B;&#x5EFA;&#x591A;&#x5BB9;&#x5668; Pod</strong></p>
<p>Create a Pod with three busy box containers with commands &#x201C;ls; sleep 3600;&#x201D;, &#x201C;echo Hello World; sleep 3600;&#x201D; and &#x201C;echo this is the third container; sleep 3600&#x201D; respectively and check the status&#x3002;</p>
<p>&#x521B;&#x5EFA;&#x4E09;&#x4E2A;&#x4F7F;&#x7528; busybox &#x955C;&#x50CF;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x5206;&#x522B;&#x5728;&#x542F;&#x52A8;&#x65F6;&#x6267;&#x884C; <code>ls;sleep 3600</code>&#x3001;<code>echo Hello World;sleep 3600</code> &#x3001;<code>echo this is the third container; sleep 3600</code> &#x3002;</p>
<p>&#x9996;&#x5148;&#xFF0C;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x5BFC;&#x51FA; YAML&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run busybox --image<span class="token operator">=</span>busybox1 -o yaml --dry-run<span class="token operator">=</span>client -- /bin/sh -c <span class="token string">&quot;ls;sleep 3600&quot;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x56E0;&#x4E3A;&#x8981;&#x6267;&#x884C;&#x547D;&#x4EE4;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x80FD;&#x4E00;&#x6B21;&#x6027;&#x8F93;&#x51FA;&#x4E09;&#x4E2A;&#x5BF9;&#x5E94;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x53EA;&#x80FD;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#xFF0C;&#x7136;&#x540E;&#x7F16;&#x8F91; YAML &#x6587;&#x4EF6;&#x3002;</p>
<p>&#x5F00;&#x59CB;&#x8F93;&#x51FA;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">creationTimestamp</span><span class="token punctuation">:</span> <span class="token null important">null</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> busybox
  <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> /bin/sh
    <span class="token punctuation">-</span> <span class="token punctuation">-</span>c
    <span class="token punctuation">-</span> ls;sleep 3600
    <span class="token key atrule">image</span><span class="token punctuation">:</span> busybox1
    <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
</code></pre>
<p>&#x590D;&#x5236; busybox1 &#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x518D;&#x521B;&#x5EFA;&#x4E24;&#x4E2A;&#x5BB9;&#x5668;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">creationTimestamp</span><span class="token punctuation">:</span> <span class="token null important">null</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> busybox
  <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> /bin/sh
    <span class="token punctuation">-</span> <span class="token punctuation">-</span>c
    <span class="token punctuation">-</span> ls;sleep 3600
    <span class="token key atrule">image</span><span class="token punctuation">:</span> busybox1
    <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> /bin/sh
    <span class="token punctuation">-</span> <span class="token punctuation">-</span>c
    <span class="token punctuation">-</span> echo Hello World;sleep 3600
    <span class="token key atrule">image</span><span class="token punctuation">:</span> busybox2
    <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> /bin/sh
    <span class="token punctuation">-</span> <span class="token punctuation">-</span>c
    <span class="token punctuation">-</span> echo this is the third container; sleep 3600
    <span class="token key atrule">image</span><span class="token punctuation">:</span> busybox3
    <span class="token key atrule">name</span><span class="token punctuation">:</span> busybox
</code></pre>
<p>&#x6709;&#x4E9B;&#x5B57;&#x6BB5;&#x662F;&#x4E0D;&#x9700;&#x8981;&#x7406;&#x4F1A;&#x7684;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">resources</span><span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token key atrule">dnsPolicy</span><span class="token punctuation">:</span> ClusterFirst
  <span class="token key atrule">restartPolicy</span><span class="token punctuation">:</span> Never
<span class="token key atrule">status</span><span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre>
<p><strong>&#x67E5;&#x770B;&#x65E5;&#x5FD7;&#xFF0C;&#x6267;&#x884C;&#x547D;&#x4EE4;</strong></p>
<p>&#x6B63;&#x5E38;&#x67E5;&#x770B;&#x65E5;&#x5FD7;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl logs <span class="token punctuation">{</span>pod<span class="token punctuation">}</span> -c <span class="token punctuation">{</span>&#x5BB9;&#x5668;&#x540D;&#x79F0;<span class="token punctuation">}</span>
</code></pre>
<p>&#x67E5;&#x770B;&#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x7684;&#x65E5;&#x5FD7;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl logs <span class="token punctuation">{</span>pod<span class="token punctuation">}</span> -c <span class="token punctuation">{</span>&#x5BB9;&#x5668;&#x540D;&#x79F0;<span class="token punctuation">}</span> --previou
</code></pre>
<p>&#x5BB9;&#x5668;&#x53EF;&#x80FD;&#x5347;&#x7EA7;&#x8FC7;&#xFF0C;&#x6216;&#x8005;&#x6302;&#x4E86;&#x91CD;&#x65B0;&#x90E8;&#x7F72;&#x8FC7;&#x7B49;&#xFF0C;&#x4F7F;&#x7528; <code>--previou</code> &#x53EF;&#x4EE5;&#x67E5;&#x770B;&#x6B64;&#x5BB9;&#x5668;&#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x7684;&#x65E5;&#x5FD7;&#x3002;</p>
<p>&#x6267;&#x884C;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token builtin class-name">exec</span> busybox -c busybox3 -- <span class="token function">ls</span>
</code></pre>
<p><strong>&#x591A;&#x5BB9;&#x5668;</strong></p>
<p>Show metrics of the above pod containers and puts them into the file.log and verify</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token function">top</span> pod busybox --containers

// putting them into <span class="token function">file</span>
kubectl <span class="token function">top</span> pod busybox --containers <span class="token operator">&gt;</span> file.log
<span class="token function">cat</span> file.log
</code></pre>
<p>Create a pod <code>mp-hello</code> with image <code>alpine</code>,<code>nginx</code> and <code>consul:1.8</code>. Use command <code>sleep infinity</code> for <code>alpine</code> container.</p>
<p>&#x53EF;&#x4EE5;&#x5148;&#x4F7F;&#x7528; <code>kubectl run mp-hello --image=alpine -o yaml --dry-run=client -- sleep infinity</code> &#x547D;&#x4EE4;&#x751F;&#x6210;&#x7B2C;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#xFF0C;&#x63A5;&#x7740;&#x590D;&#x5236;&#x53E6;&#x5916;&#x4E24;&#x4E2A;&#x5BB9;&#x5668;&#x3002;</p>
<p>&#x6838;&#x5FC3;&#x90E8;&#x5206;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">args</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> sleep
    <span class="token punctuation">-</span> infinity
    <span class="token key atrule">image</span><span class="token punctuation">:</span> alpine
    <span class="token key atrule">name</span><span class="token punctuation">:</span> alpine
  <span class="token punctuation">-</span> <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
  <span class="token punctuation">-</span> <span class="token key atrule">image</span><span class="token punctuation">:</span> consul<span class="token punctuation">:</span><span class="token number">1.8</span>
    <span class="token key atrule">name</span><span class="token punctuation">:</span> consul
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x591A;&#x4E2A;&#x955C;&#x50CF;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x955C;&#x50CF;&#x9700;&#x8981;&#x5E26; <code>-</code>&#xFF0C;&#x5426;&#x5219;&#x53EA;&#x4F1A;&#x751F;&#x6548;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x3002;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x662F;&#x9519;&#x8BEF;&#x7684;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">image</span><span class="token punctuation">:</span> alpine
    <span class="token key atrule">name</span><span class="token punctuation">:</span> alpine
    <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">image</span><span class="token punctuation">:</span> consul<span class="token punctuation">:</span><span class="token number">1.8</span>
    <span class="token key atrule">name</span><span class="token punctuation">:</span> consul
</code></pre>
<p><strong>&#x6807;&#x7B7E;</strong></p>
<p>&#x663E;&#x793A;&#x6240;&#x6709;&#x6807;&#x7B7E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods --show-labels
</code></pre>
<p>&#x521B;&#x5EFA; Pod &#x65F6;&#x8BBE;&#x7F6E;&#x6807;&#x7B7E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run nginx-dev1 --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never --labels<span class="token operator">=</span>env<span class="token operator">=</span>dev
</code></pre>
<p>&#x67E5;&#x627E;&#x663E;&#x793A; env &#x6807;&#x7B7E;&#x7684;&#x503C;&#x4E3A; dev &#x7684; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -l <span class="token assign-left variable">env</span><span class="token operator">=</span>dev
</code></pre>
<p>&#x67E5;&#x627E;&#x663E;&#x793A; env &#x6807;&#x7B7E;&#x7684;&#x503C;&#x4E3A; dev &#x7684; Pod&#xFF0C;&#x540C;&#x65F6;&#x8F93;&#x51FA; Pod &#x5177;&#x6709;&#x7684;&#x6807;&#x7B7E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -l <span class="token assign-left variable">env</span><span class="token operator">=</span>dev --show-labels
</code></pre>
<p>&#x5177;&#x6709;&#x67D0;&#x4E2A;&#x6807;&#x7B7E;&#x7684; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -l <span class="token builtin class-name">test</span> --show-labels
</code></pre>
<blockquote>
<p>&#x6709;&#x4E9B;&#x6587;&#x6863;&#x5199;&#x6210; <code>kubectl get pods -L env</code> &#x662F;&#x9519;&#x7684;&#xFF0C;&#x662F;&#x5C0F;&#x5199; l&#xFF0C;&#x4E0D;&#x662F;&#x5927;&#x5199; L&#x3002;&#x5982;&#x679C;&#x4F7F;&#x7528; <code>-L</code>&#xFF0C;&#x4F1A;&#x5BFC;&#x81F4;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x7B5B;&#x9009;&#x6548;&#x679C;&#x3002;</p>
</blockquote>
<p>&#x6807;&#x7B7E;&#x7684;&#x503C;&#x662F;&#x67D0;&#x4E00;&#x79CD;&#x5373;&#x53EF;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -l <span class="token string">&apos;env in (dev,prod)&apos;</span>
</code></pre>
<p>&#x8986;&#x76D6;&#x6807;&#x7B7E;&#x7684;&#x503C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl label pod/nginx-dev3 <span class="token assign-left variable">env</span><span class="token operator">=</span>uat --overwrite
</code></pre>
<p>&#x79FB;&#x9664;&#x6807;&#x7B7E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl label pod/nginx-dev3 env-
</code></pre>
<blockquote>
<p>&#x589E;&#x52A0;&#x6807;&#x7B7E;&#x79FB;&#x9664;&#x6807;&#x7B7E;&#x4E0D;&#x9700;&#x8981;&#x52A0;&#x4E0A; <code>-l</code> &#x6216; <code>-label</code>&#x3002;&#x7B5B;&#x9009;&#x5BF9;&#x8C61;&#x624D;&#x9700;&#x8981;&#x52A0;&#x4E0A;  <code>-l</code> &#x6216; <code>-label</code>&#x3002;</p>
</blockquote>
<p>annotation &#x4E5F;&#x662F;&#x7C7B;&#x4F3C;&#xFF0C;&#x4F46;&#x662F; annotation &#x7684;&#x547D;&#x4EE4;&#x5173;&#x952E;&#x5B57;&#x662F; annotate&#xFF0C;&#x800C;&#x4E0D;&#x662F; annotation &#x3002;</p>
<pre class="language-"><code class="lang-bash"> kubectl annotate  node node01 flagship-
</code></pre>
<p><strong>&#x4F38;&#x7F29;</strong></p>
<p>&#x521B;&#x5EFA;&#x5177;&#x6709;&#x591A;&#x4E2A;&#x5B9E;&#x4F8B;&#x7684; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create deployment webapp --image<span class="token operator">=</span>nginx --replicas<span class="token operator">=</span><span class="token number">5</span>
</code></pre>
<p>&#x6269;&#x5BB9;&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl scale deployment webapp --replicas<span class="token operator">=</span><span class="token number">5</span>
</code></pre>
<p><strong>Job&#x3001;CronJob</strong></p>
<p>&#x521B;&#x5EFA; Job&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create job nodeversion --image<span class="token operator">=</span>node
<span class="token comment"># kubectl create job nodeversion --image=node -- node -v</span>
</code></pre>
<p>&#x521B;&#x5EFA;&#x5177;&#x6709;&#x8868;&#x8FBE;&#x5F0F;&#x7684; CronJob&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create cronjob date-job --image<span class="token operator">=</span>busybox --schedule<span class="token operator">=</span><span class="token string">&quot;*/1 * * * *&quot;</span>
</code></pre>
<p><strong>PV&#x3001;PVC</strong></p>
<p>&#x672C;&#x8282;&#x4E2D;&#x4ECB;&#x7ECD;&#x7684;&#x53EA;&#x662F;&#x6D41;&#x7A0B;&#xFF0C;&#x4E0D;&#x540C;&#x53EF;&#x80FD;&#x8BB0;&#x4F4F;&#x5168;&#x90E8; YAML &#x7684;&#xFF0C;&#x505A;&#x9898;&#x7684;&#x65F6;&#x5019;&#x770B;&#x5B98;&#x65B9;&#x6587;&#x6863;&#x590D;&#x5236;&#x4E0B;&#x8F7D;&#xFF1A;</p>
<p>Create a hostPath PersistentVolume named task-pv-volume with storage 10Gi, access modes ReadWriteOnce, storageClassName manual, and volume at /mnt/data and verify.</p>
<p>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x79F0;&#x4E3A; task-pv-volume &#x7684; hostPath &#x7C7B;&#x578B;&#x7684; PV &#x5377;&#xFF0C;&#x5176;&#x6620;&#x5C04;&#x672C;&#x5730;&#x76EE;&#x5F55;&#x4E3A; <code>/mnt/data</code>&#xFF0C;&#x5377;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;&#x4E3A; 10Gi&#xFF0C;&#x4F7F;&#x7528; <code>ReadWriteOnce</code> &#x8BBF;&#x95EE;&#x6A21;&#x5F0F;&#xFF0C;<code>storageClassName: manual</code>&#x3002;</p>
<p>storageClassName &#x662F;&#x7ED9;&#x5377;&#x8FDB;&#x884C;&#x5206;&#x7C7B;&#xFF0C;&#x5176;&#x5B57;&#x6BB5;&#x503C;&#x662F;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x3002;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> PersistentVolume
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>volume
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">type</span><span class="token punctuation">:</span> local
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">storageClassName</span><span class="token punctuation">:</span> manual
  <span class="token key atrule">capacity</span><span class="token punctuation">:</span>
    <span class="token key atrule">storage</span><span class="token punctuation">:</span> 10Gi
  <span class="token key atrule">accessModes</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> ReadWriteOnce
  <span class="token key atrule">hostPath</span><span class="token punctuation">:</span>
    <span class="token key atrule">path</span><span class="token punctuation">:</span> <span class="token string">&quot;/mnt/data&quot;</span>
</code></pre>
<p>&#x58F0;&#x660E; PVC&#xFF0C;&#x5373;&#x4EE3;&#x8868;&#x8981;&#x4F7F;&#x7528;&#x591A;&#x5927;&#x7684;&#x5377;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> PersistentVolumeClaim
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>claim
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">storageClassName</span><span class="token punctuation">:</span> manual
  <span class="token key atrule">accessModes</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> ReadWriteOnce
  <span class="token key atrule">resources</span><span class="token punctuation">:</span>
    <span class="token key atrule">requests</span><span class="token punctuation">:</span>
      <span class="token key atrule">storage</span><span class="token punctuation">:</span> 3Gi
</code></pre>
<p>&#x6302;&#x8F7D;&#x5230; Pod &#x4E2D;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>pod
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>storage
      <span class="token key atrule">persistentVolumeClaim</span><span class="token punctuation">:</span>
        <span class="token key atrule">claimName</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>claim
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>container
      <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
      <span class="token key atrule">ports</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> <span class="token key atrule">containerPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
          <span class="token key atrule">name</span><span class="token punctuation">:</span> <span class="token string">&quot;http-server&quot;</span>
      <span class="token key atrule">volumeMounts</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> <span class="token key atrule">mountPath</span><span class="token punctuation">:</span> <span class="token string">&quot;/usr/share/nginx/html&quot;</span>
          <span class="token key atrule">name</span><span class="token punctuation">:</span> task<span class="token punctuation">-</span>pv<span class="token punctuation">-</span>storage
</code></pre>
<p><strong>ConfigMap</strong></p>
<p>&#x521B;&#x5EFA; configmap&#xFF0C;&#x5176;&#x5185;&#x5BB9;&#x6765;&#x7740;&#x952E;&#x503C;&#x5BF9;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create cm myconfigmap --from-literal<span class="token operator">=</span>appname<span class="token operator">=</span>myapp
</code></pre>
<blockquote>
<p><code>--from-literal</code> &#x6765;&#x7740;&#x952E;&#x503C;&#x5BF9;&#xFF0C;&#x6BCF;&#x6B21;&#x53EA;&#x80FD;&#x586B;&#x5199;&#x4E00;&#x4E2A;&#x952E;&#x503C;&#x5BF9;&#xFF0C;<code>--from-file</code> &#x6765;&#x81EA;&#x6587;&#x4EF6;&#x6216;&#x6587;&#x4EF6;&#x5939;&#x3002;</p>
</blockquote>
<p>&#x4ECE;&#x6587;&#x4EF6;&#x4E2D;&#x751F;&#x6210;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token function">cat</span> <span class="token operator">&gt;&gt;</span> config.txt <span class="token operator">&lt;&lt;</span> <span class="token string">EOF
key1=value1
key2=value2
EOF</span>
</code></pre>
<pre class="language-"><code class="lang-bash">kubectl create cm keyvalcfgmap --from-file<span class="token operator">=</span>config.txt
</code></pre>
<p>&#x5728; Pod &#x4E2D;&#x4F7F;&#x7528;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Pod
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">creationTimestamp</span><span class="token punctuation">:</span> <span class="token null important">null</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">run</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">resources</span><span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token key atrule">envFrom</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">configMapRef</span><span class="token punctuation">:</span>
        <span class="token key atrule">name</span><span class="token punctuation">:</span> keyvalcfgmap
  <span class="token key atrule">dnsPolicy</span><span class="token punctuation">:</span> ClusterFirst
  <span class="token key atrule">restartPolicy</span><span class="token punctuation">:</span> Never
<span class="token key atrule">status</span><span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre>
<p>&#x4E3B;&#x8981;&#x662F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">    envFrom:
    - configMapRef:
        name: keyvalcfgmap
</code></pre>
<p>&#x5982;&#x679C;&#x53EA;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x952E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">    env:
    - name: ENVIRONMENT
      valueFrom:
        configMapKeyRef:
          name: envcfgmap
          key: environment
</code></pre>
<p>&#x7136;&#x540E;&#x662F; <code>--from-env-file</code>&#x3002;</p>
<p>Create an env file file.env with var1=val1 and create a configmap envcfgmap from this env file and verify the configmap</p>
<pre class="language-"><code class="lang-bash"><span class="token builtin class-name">echo</span> <span class="token assign-left variable">var1</span><span class="token operator">=</span>val1 <span class="token operator">&gt;</span> file.env
<span class="token function">cat</span> file.env

kubectl create cm envcfgmap --from-env-file<span class="token operator">=</span>file.env
</code></pre>
<p>&#x5FD8;&#x8BB0; <code>--from...</code> &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E0D;&#x8981;&#x67E5; kubernetes&#xFF0C;&#x800C;&#x662F;&#x4F7F;&#x7528; <code>kubectl create configmap --help</code> &#x5FEB;&#x901F;&#x67E5;&#x8BE2;&#x6587;&#x6863;&#x3002;</p>
<p><strong>Secret</strong></p>
<p>secret &#x8DDF; comfigmap &#x7C7B;&#x4F3C;&#xFF0C;&#x521B;&#x5EFA; secret&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create secret generic my-secret --from-literal<span class="token operator">=</span><span class="token string">&apos;username=user&apos;</span> --from-literal<span class="token operator">=</span><span class="token string">&apos;password=mypassword&apos;</span>
</code></pre>
<p>&#x6620;&#x5C04;&#x5230; Pod &#x4E2D;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">env</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> USER_NAME
      <span class="token key atrule">valueFrom</span><span class="token punctuation">:</span>
        <span class="token key atrule">secretKeyRef</span><span class="token punctuation">:</span>
          <span class="token key atrule">name</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>secret
          <span class="token key atrule">key</span><span class="token punctuation">:</span> username
</code></pre>
<p><strong>SecurityContext</strong></p>
<p>Create a pod called secbusybox with the image busybox which executes command sleep 3600 and makes sure any Containers in the Pod, all processes run with user ID 1000 and with group id 2000 and verify.</p>
<p>&#x6838;&#x5FC3;&#x90E8;&#x5206;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">securityContext</span><span class="token punctuation">:</span> <span class="token comment"># add security context</span>
    <span class="token key atrule">runAsUser</span><span class="token punctuation">:</span> <span class="token number">1000</span>
    <span class="token key atrule">runAsGroup</span><span class="token punctuation">:</span> <span class="token number">2000</span>
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x9A8C;&#x8BC1;&#xFF0C;&#x5219;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl <span class="token builtin class-name">exec</span> -it secbusybox -- <span class="token function">sh</span>
</code></pre>
<p>Create pod with an nginx image and configure the pod with capabilities NET_ADMIN and SYS_TIME verify the capabilities.</p>
<p>&#x683C;&#x5F0F;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">securityContext</span><span class="token punctuation">:</span>
      <span class="token key atrule">capabilities</span><span class="token punctuation">:</span>
        <span class="token key atrule">drop</span><span class="token punctuation">:</span>
          <span class="token punctuation">-</span> all
        <span class="token key atrule">add</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>&#x201C;NET_ADMIN&#x201D;<span class="token punctuation">]</span>
</code></pre>
<p>&#x6309;&#x7167;&#x9898;&#x76EE;&#xFF0C;&#x6838;&#x5FC3;&#x90E8;&#x5206;&#x662F;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">containers</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">securityContext</span><span class="token punctuation">:</span>
      <span class="token key atrule">capabilities</span><span class="token punctuation">:</span>
        <span class="token key atrule">add</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&quot;SYS_TIME&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;NET_ADMIN&quot;</span><span class="token punctuation">]</span>
</code></pre>
<p><strong>ServiceAccount</strong></p>
<p>&#x521B;&#x5EFA; ServiceAccount&#xFF1A;</p>
<pre class="language-"><code>kubectl create sa admin
</code></pre><p>&#x5728; Pod &#x4E2D;&#x4F7F;&#x7528;&#x6B64; ServiceAccount&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">spec:
  serviceAccountName: admin
</code></pre>
<p><strong>&#x8D44;&#x6E90;&#x9650;&#x5236;</strong></p>
<p>Create a Pod nginx and specify a memory request and a memory limit of 100Mi and 200Mi respectively.</p>
<p>&#x6838;&#x5FC3;&#x90E8;&#x5206;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">resources</span><span class="token punctuation">:</span> 
      <span class="token key atrule">requests</span><span class="token punctuation">:</span>
        <span class="token key atrule">memory</span><span class="token punctuation">:</span> <span class="token string">&quot;100Mi&quot;</span>
      <span class="token key atrule">limits</span><span class="token punctuation">:</span>
        <span class="token key atrule">memory</span><span class="token punctuation">:</span> <span class="token string">&quot;200Mi&quot;</span>
</code></pre>
<p>Create a Pod nginx and specify a CPU request and a CPU limit of 0.5 and 1 respectively.</p>
<p>&#x6838;&#x5FC3;&#x90E8;&#x5206;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">resources</span><span class="token punctuation">:</span>
      <span class="token key atrule">requests</span><span class="token punctuation">:</span>
        <span class="token key atrule">cpu</span><span class="token punctuation">:</span> <span class="token string">&quot;0.5&quot;</span>
      <span class="token key atrule">limits</span><span class="token punctuation">:</span>
        <span class="token key atrule">cpu</span><span class="token punctuation">:</span> <span class="token string">&quot;1&quot;</span>
</code></pre>
<p><strong>&#x53EF;&#x89C2;&#x6D4B;&#x6027;</strong></p>
<p>Pod &#x6709;&#x542F;&#x52A8;&#x68C0;&#x67E5;&#x3001;&#x5C31;&#x7EEA;&#x68C0;&#x67E5;&#x3001;&#x5065;&#x5EB7;&#x68C0;&#x67E5;&#xFF0C;&#x68C0;&#x6D4B;&#x65B9;&#x5F0F;&#x6709; TCP&#x3001;HTTP&#x3001;&#x547D;&#x4EE4;&#x7B49;&#x3002;</p>
<p>&#x53C2;&#x8003; </p>
<p><a href="https://kubernetes.io/zh/docs/concepts/workloads/pods/pod-lifecycle/#container-probes" target="_blank">https://kubernetes.io/zh/docs/concepts/workloads/pods/pod-lifecycle/#container-probes</a></p>
<p><a href="https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes" target="_blank">https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes</a></p>
<p>&#x542F;&#x52A8;&#x68C0;&#x67E5;&#xFF1A;startupProbe&#xFF1B;</p>
<p>&#x5C31;&#x7EEA;&#x68C0;&#x67E5;&#xFF1A;readinessProbe&#xFF1B;</p>
<p>&#x5065;&#x5EB7;&#x68C0;&#x67E5;&#xFF1A;livenessProbe&#xFF1B;</p>
<p>&#x4E24;&#x4E2A;&#x5E38;&#x7528;&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li><code>initialDelaySeconds</code>&#xFF1A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x540E;&#x8981;&#x7B49;&#x5F85;&#x591A;&#x5C11;&#x79D2;&#x540E;&#x5B58;&#x6D3B;&#x548C;&#x5C31;&#x7EEA;&#x63A2;&#x6D4B;&#x5668;&#x624D;&#x88AB;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F; 0 &#x79D2;&#xFF0C;&#x6700;&#x5C0F;&#x503C;&#x662F; 0&#x3002;</li>
<li><code>periodSeconds</code>&#xFF1A;&#x6267;&#x884C;&#x63A2;&#x6D4B;&#x7684;&#x65F6;&#x95F4;&#x95F4;&#x9694;&#xFF08;&#x5355;&#x4F4D;&#x662F;&#x79D2;&#xFF09;&#x3002;&#x9ED8;&#x8BA4;&#x662F; 10 &#x79D2;&#x3002;&#x6700;&#x5C0F;&#x503C;&#x662F; 1&#x3002;</li>
</ul>
<p>&#x547D;&#x4EE4;&#x5F62;&#x5F0F;&#x7684;&#x68C0;&#x67E5;&#xFF1A;</p>
<pre class="language-"><code>    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre><p>HTTP &#x5F62;&#x5F0F;&#x7684;&#x68C0;&#x67E5;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">  <span class="token key atrule">httpGet</span><span class="token punctuation">:</span>
    <span class="token key atrule">httpHeaders</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> Accept
        <span class="token key atrule">value</span><span class="token punctuation">:</span> application/json
</code></pre>
<p>TCP&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">      <span class="token key atrule">tcpSocket</span><span class="token punctuation">:</span>
        <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8080</span>
</code></pre>
<p><strong>&#x7F51;&#x7EDC;</strong></p>
<p>&#x521B;&#x5EFA;&#x5E26;&#x7AEF;&#x53E3;&#x7684; Pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl run nginx --image<span class="token operator">=</span>nginx --restart<span class="token operator">=</span>Never --port<span class="token operator">=</span><span class="token number">80</span>
</code></pre>
<p>&#x4E3A;&#x4E00;&#x4E2A; Pod &#x66B4;&#x9732;&#x7AEF;&#x53E3;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl expose po nginx --port<span class="token operator">=</span><span class="token number">80</span> --type<span class="token operator">=</span>NodePort
</code></pre>
<p>&#x6620;&#x5C04;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x7AEF;&#x53E3;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl expose po nginx --port<span class="token operator">=</span><span class="token number">80</span> --target-port<span class="token operator">=</span><span class="token number">8080</span> --type<span class="token operator">=</span>NodePort
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x75F4;&#x8005;&#x5DE5;&#x826F; 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x6863;&#x6700;&#x540E;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2021-11-13 09:55:48
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="8.health/README.md" class="navigation navigation-prev " aria-label="Previous page: 导读">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="ckad.html" class="navigation navigation-next " aria-label="Next page: CKAD 认证帮助">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Kubernetes 命令概览","level":"1.9","depth":1,"next":{"title":"CKAD 认证帮助","level":"1.10","depth":1,"path":"ckad.md","ref":"ckad.md","articles":[]},"previous":{"title":"导读","level":"1.8.1","depth":2,"path":"8.health/README.md","ref":"8.health/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["tbfed-pagefooter","anchor-navigation-ex","mermaid-gb3","insert-logo","chapter-fold","advanced-emoji","github","splitter","alerts","popup","prism","-highlight","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 痴者工良 2021","modify_label":"文档最后更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"prism":{"lang":{"flow":"typescript","shell":"bash"},"ignore":["mermaid","eval-js"],"css":["prismjs/themes/prism.css"],"js":["prismjs/prism.js","prismjs/components.js","prismjs/components/prism-go.min.js","prismjs/components/prism-yaml.min.js","prismjs/components/prism-bash.min.js","prismjs/components/prism-shell-session.min.js"]},"github":{"url":"https://github.com/whuanle/kubernetes"},"livereload":{},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"alerts":{},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"/images/logo.jpg"}},"theme":"default","author":"痴者工良","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Kubernetes - 痴者工良","language":"zh-hans","links":{"sidebar":{"痴者工良的博客":"https://www.whuanle.cn"}},"gitbook":"*","description":"这是一本关于 Kubernetes 的书，作者 痴者工良"},"file":{"path":"k8s.md","mtime":"2021-11-13T01:55:48.243Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-16T23:21:22.294Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

